<template>
    
    <el-popover  placement="bottom" width="600" trigger="click" class="">
        <el-form size="mini" label-width="180px" class="mini-form min-form" style="text-align:left;">
            <el-form-item label="转换比例"><exInput v-model.number="cfg.amountUnit" size="mini"></exInput></el-form-item>
            <el-divider></el-divider>
            <el-form-item label="查询间隔(毫秒)"><exInput v-model.number="cfg.sleepTime" size="mini"></exInput></el-form-item>
            <el-divider></el-divider>
            <!-- <el-form-item label="数据库主机"><exInput v-model.number="cfg.db.host" size="mini"></exInput></el-form-item>
            <el-form-item label="端口"><exInput v-model.number="cfg.db.port" size="mini"></exInput></el-form-item>
            <el-form-item label="用户名"><exInput v-model.number="cfg.db.user" size="mini"></exInput></el-form-item>
            <el-form-item label="密码"><exInput v-model.number="cfg.db.password" size="mini"></exInput></el-form-item>
            <el-form-item label="数据库"><exInput v-model.number="cfg.db.database" size="mini"></exInput></el-form-item>
            <el-divider></el-divider> -->
            <el-form-item label="证券帐号"><exInput v-model.number="cfg.account" size="mini"></exInput></el-form-item>
            <el-divider></el-divider>
            <el-form-item label="事件开关:"></el-form-item>
            <el-form-item label="分时图-放量">
                <exSwitch v-model="cfg.event.chart_time_num" title="分时成交量超过最低量,且成交量比前3分钟的量都高出指定倍数"></exSwitch>
                <exInput label="最低量" v-model.number="cfg.event.chart_time_num_min" width="80"></exInput>
                <exInput label="倍数" v-model.number="cfg.event.chart_time_num_bet" width="80"></exInput>
            </el-form-item>
            <el-form-item label="分时图-区间新高/新低">
                <exSwitch v-model="cfg.event.chart_time_range" title="分时图在指定的时间范围(比如最近20分钟)内出现新高/新低"></exSwitch>
                <exInput label="区间(分钟)" v-model.number="cfg.event.chart_time_range_minute" width="80"></exInput>
            </el-form-item>
            <el-form-item label="主力资金"><exSwitch v-model="cfg.event.main_money" title="主力资金流入/流出变化提醒"></exSwitch></el-form-item>
            <el-form-item label="港通资金"><exSwitch v-model="cfg.event.gt_money" title="港通资金流入/流出变化提醒"></exSwitch></el-form-item>
            <el-form-item label="个股明细-区间振幅">
                <exSwitch v-model="cfg.event.detail_wave" title="指定时间内的波动超过指定幅度"></exSwitch>
                <exInput label="异常间隔(秒)" v-model.number="cfg.diffTime" width="80"></exInput>
                <exInput label="异常幅度" v-model.number="cfg.wave" width="80"></exInput>
            </el-form-item>
            <el-form-item label="个股明细-明细放量">
                <exSwitch v-model="cfg.event.detail_num" title="最近10笔成交量有3笔以上达到指定金额"></exSwitch>
                <exInput label="价格<100" v-model.number="cfg.event.detail_num_low" width="80" title="不低于100手"></exInput>
                <exInput label="价格>=100" v-model.number="cfg.event.detail_num_high" width="80" title="不低于50手"></exInput>
            </el-form-item>
            <el-form-item label="个股明细-新高/新低"><exSwitch v-model="cfg.event.detail_newpoint"></exSwitch></el-form-item>
            <el-form-item label="个股明细-东财异动"><exSwitch v-model="cfg.event.detail_dfcf"></exSwitch></el-form-item>
            <el-form-item label="个股明细-涨停板挂单变量">
                <exSwitch v-model="cfg.event.detail_zt_num"  title="涨停板的封单变化量,在两次查询间隔内超出指定数量"></exSwitch>
                <exInput label="变量(手)" v-model.number="cfg.event.detail_zt_num_diff" width="80" title="不低于500手"></exInput>
            </el-form-item>
            <el-divider></el-divider>
                <el-form-item label="开盘啦模式">
                    <exSwitch v-model="cfg.kplMode"></exSwitch>
                    <!-- <el-link type="primary" size="mini" @click="getKplList" class="ml10">获取kpl自选列表</el-link> -->
                </el-form-item>
            <el-divider></el-divider>
            <el-row class="right">
                <el-link type="success" size="mini" @click="saveConfig" class="ml10">保存配置</el-link>
                <el-link type="primary" size="mini" @click="tipsTest()" class="ml10">提示测试1</el-link>
                <el-link type="primary" size="mini" @click="tipsTest('big')" class="ml10">提示测试2</el-link>
                <el-link type="primary" size="mini" @click="dbConTest" class="ml10">链接测试</el-link>
                <el-link type="primary" size="mini" @click="dbQryTest" class="ml10">查询测试</el-link>
                <!-- <el-link type="primary" size="mini" @click="dbAddTest" class="ml10">插入测试</el-link> -->
            </el-row>
            <el-row>
            </el-row>
        </el-form>
        <el-button slot="reference" type="text" class="ml10" size="mini">配置信息</el-button>
    </el-popover>
</template>

<script>

export default {
    data() {
        return {
        }
    },
    inject: ['cfg',"isQry","getSleepTime","isMoneyException","addException"],
    

    mounted() {
        
    },

    methods: {
        getKplList(){
            var that = this;
            if(!window.electron){
                return;
            }
            this.registerListen(this,"getKplList",(cfg)=>{
                try{
                    that.$message.success("列表获取成功")
                }catch(ex){
                    that.$message.error("列表获取异常:"+ex.message)
                }
            });
            electron.ipcRenderer.send("getKplList","")
        },
        saveConfig(){
            this.$emit("saveConfig")
        },
        tipsTest(type){
            if(!window.electron){
                return;
            }
            var msg = `<span class='red'>稳健医疗&nbsp;(300888)<br/>&nbsp;&nbsp;&nbsp;&nbsp;wave:&nbsp;&nbsp;1.5%<br/>145.5&nbsp;(4.02%)<br/>13:20:22->13:21:10<br/>143.2->145.5</span>`
                    
            electron.ipcRenderer.send("showBox","提示信息测试",type);
        },
        dbAddTest(){
            if(!window.electron){
                return;
            }
            var that = this;
            var param = {type:"insertHis",name:"insertHis",objInfo:{tradeno:22,day:33,time:44,code:55,name:66}};
            electron.ipcRenderer.send("doSql",param)
            
            this.registerListen(this,param.name,(res)=>{
                try{
                    console.info(param.name+'Res dbdata:',res);
                    if(res.succ){
                        that.$message.success(JSON.stringify(res.data));
                    }else{
                        that.$message.error(res.err)
                    }
                }catch(ex){
                    that.$message.error("查询异常:"+ex.message)
                }
            });
        },
        dbQryTest(){
            if(!window.electron){
                return;
            }
            var that = this;
            var param = {type:"queryHis",name:"queryHis",objInfo:{day:"20001028"}};
            electron.ipcRenderer.send("doSql",param)
            
            this.registerListen(this,param.name,(res)=>{
                try{
                    console.info(param.name+'Res dbdata:',res);
                    if(res.succ){
                        that.$message.success("查询成功"+JSON.stringify(res.data));
                    }else{
                        that.$message.error(res.err)
                    }
                }catch(ex){
                    that.$message.error("查询异常:"+ex.message)
                }
            });
        },
        dbConTest(){

            if(!window.electron){
                return;
            }
            var that = this;
            electron.ipcRenderer.send("reCon","")
            
            this.registerListen(this,"reCon",(err)=>{
                try{
                    if(err){
                        that.$message.error("数据读取异常:"+err)
                    }else{
                        that.$message.success("数据读取成功");
                    }
                }catch(ex){
                    that.$message.error("数据读取异常:"+ex.message)
                }
            });
        },
    }
}
</script>


